﻿<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>选择设备属性</title>  
     <base target="_self"/>
    <%@include file="../jslib/jquerylib.jsp" %>
    <link rel="stylesheet" type="text/css" href="<%=path %>/web/style/layout.css" />
    <script type="text/javascript" src="<%=path %>/jslib/jquery.validate.min.js"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/jquery.form.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/additional-methods.js"></script>
  </head>
  <script>
         var shebeishuxingids = '';
         var shuxingnames = '';
  		$(document).ready(function(){
			 	 
			    $('input[type="text"]').addClass('input_text');
				$("#fromTable").jqGrid({
					url:common_basePath+'eqAction!queryShebeishuxingList.action?type=0&mainid=<%=request.getParameter("mainid")%>&temp='+Math.round(Math.random()*10000),
					datatype: "json",
					width : 350,
		            height : 380,
					colNames:['主键','设备属性'],
					colModel:[{name:'ID',index:'ID',key:true,hidden:true, width:100,hidedlg:true},
					          {name:'SHUXINGNAME',index:'SHUXINGNAME', width:200}
					        ],
					shrinkToFit:false,
					sortname:'ID',
					sortorder:'desc',
					viewrecords:true,
					multiselect: true, // 是否显示复选框
					multiboxonly : true, 
					rownumbers: false,//显示行号
					editable:true, 
					rowNum:15,
					rowList:[15,20,50,200,500],
					toolbar: [false,"top"],
					jsonReader: {
						root:"rows",		// 数据行（默认为：rows）
						page: "page",  	// 当前页
						total: "total",  // 总页数
						records: "records",  // 总记录数
						repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
					},
					prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
					pager:"#fromPager",
					caption: "设备属性列表"
				});
				
				//已选项目列表
				$("#toTable").jqGrid({
					url:common_basePath+'eqAction!queryShebeishuxingList.action?type=1&mainid=<%=request.getParameter("mainid")%>&temp='+Math.round(Math.random()*10000),
					datatype: "json",
					width : 350,
		            height : 380,
					colNames:['主键','设备属性'],
					colModel:[{name:'ID',index:'ID',key:true,hidden:true, width:100,hidedlg:true},
					          {name:'SHUXINGNAME',index:'SHUXINGNAME', width:200}
					        ],
					shrinkToFit:false,
					sortname:'ID',
					sortorder:'desc',
					viewrecords:true,
					multiselect: true, // 是否显示复选框
					multiboxonly : true, 
					rownumbers: false,//显示行号
					editable:true, 
					ondblClickRow : function(rowid) {
					var row = $("#toTable").jqGrid('getRowData', rowid);
						$("#fromTable").jqGrid('addRowData', rowid, row);
						$("#toTable").jqGrid('delRowData', rowid);
					},
					rowNum:15,
					rowList:[15,20,50,200,500],
					toolbar: [false,"top"],
					jsonReader: {
						root:"rows",		// 数据行（默认为：rows）
						page: "page",  	// 当前页
						total: "total",  // 总页数
						records: "records",  // 总记录数
						repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
					},
					prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
					pager:"#toPager",
					caption: "已选设备属性列表"
				});
				
				//选择按钮
				$("#to").click(function() {
				       var s = $("#fromTable").jqGrid('getGridParam', 'selarrrow') + "";
						var to = $("#toTable").jqGrid('getDataIDs') + "";
						if (s) {
							var ids = s.split(",");
							var toIds = to ? to.split(",") : [];
							for ( var i = 0; i < ids.length; i++) {
								var id = ids[i];
								var row = $("#fromTable").jqGrid('getRowData', id);
								var flag = true;
								for ( var j = 0; j < toIds.length; j++) {
									var toId = toIds[j];
									var toRow = $("#toTable").jqGrid('getRowData', toId);
									if (row['ID'] == toRow['ID']) {
										flag = false;
										break;
									}
								}
								if (flag) {
									$("#toTable").jqGrid('addRowData', id, row);
									$("#fromTable").jqGrid('delRowData', id);
								}
							}
						}
						var to = $("#toTable").jqGrid('getDataIDs') + "";
						var toIdArr = [];
						var toIds = to ? to.split(",") : [];
						for ( var j = 0; j < toIds.length; j++) {
							var toId = toIds[j];
							var toRow = $("#toTable").jqGrid('getRowData', toId);
							toIdArr.push(toRow['userid']);
						}
					});
					//删除已选的检测项目
					$("#from").click(function() {
					    var biaozhunIds = [];
						var s = $("#toTable").jqGrid('getGridParam', 'selarrrow') + "";
						if (s) {
							var ids = s.split(",");
							var toIds = to ? to.split(",") : [];
							for ( var i = 0; i < ids.length; i++) {
								var id = ids[i];
								var row = $("#toTable").jqGrid('getRowData', id);
								var flag = true;
								for ( var j = 0; j < toIds.length; j++) {
									var toId = toIds[j];
									var toRow = $("#fromTable").jqGrid('getRowData', toId);
									if (row['ID'] == toRow['ID']) {
										flag = false;
										break;
									}
								}
								if (flag) {
									$("#fromTable").jqGrid('addRowData', id, row);
									$("#toTable").jqGrid('delRowData', id);
								}
							}
						}
						var to = $("#toTable").jqGrid('getDataIDs') + "";
						var toIdArr = [];
						var toIds = to ? to.split(",") : [];
						for ( var j = 0; j < toIds.length; j++) {
							var toId = toIds[j];
							var toRow = $("#toTable").jqGrid('getRowData', toId);
							toIdArr.push(toRow['ID']);
						}
					
					});
				
					/**
					 * 确定
					 */
					$("#clos").click(function() {
					    var s = $("#toTable").jqGrid('getDataIDs') + "";
						var result = s+"@";
						if (s) {
							var ids = s.split(",");
							for ( var i = 0; i < ids.length; i++) {
								var id = ids[i];
								var row = $("#toTable").jqGrid('getRowData', id);
								result = result+row.SHUXINGNAME+",";
							}
						}
						window.returnValue = result;
						window.close();
					});
			});
		function gridSearch(){
		    var shebeishuxing = $("#shebeishuxing").val();
			var params = {  
			          "shebeishuxing" : encodeURIComponent($.trim(shebeishuxing))
			};							 
			 var postData = $("#fromTable").jqGrid("getGridParam", "postData");
			 $.extend(postData, params);
			jQuery("#fromTable").jqGrid('setGridParam',
			{
				url:common_basePath+'eqAction!queryShebeishuxingList.action?type=0&mainid=<%=request.getParameter("mainid")%>&temp='+Math.round(Math.random()*10000)
			}).trigger("reloadGrid", [{page:1}]); 
		}
		
		function selectData(id,tablename,colname,disname,cnname,fieldslist,formid){
		  
		    var   datas = window.showModalDialog("<%=request.getContextPath()%>/auto!chooseDatalist.action?byTableValueId=null&tablename="+tablename+"&colname="+colname+"&disname="+disname+"&cnname="+escape(encodeURIComponent(cnname))+"&formid="+formid+"&fileName="+id+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=500px;dialogHeight=400px");
		       if(typeof(datas) == 'undefined'){
			   }else{
				 var json1 = eval('(' + datas + ')');
				 document.getElementById(id).value = json1.ID;
				
				 var disnamearray = disname.split(',');
				 //检测项目管理  添加页面选择检测单位
				 if(id=='T_JIANCEDANWEI'){
				     $("#data_T_JIANCEDANWEI").val(json1.T_JIANCEDANWEI);  
				     $("#T_JIANCEDANWEI").val(json1.ID);
				 }
				 if(id=='T_JIANCEDIDIAN'){
				     $("#data_T_JIANCEDIDIAN").val(json1.T_JIANCEDANWEI);  
				     $("#T_JIANCEDIDIAN").val(json1.ID);
				 }
			  }
		}
		
		//右侧列表刷新
		function gridSearchYou(){
			 jQuery("#toTable").jqGrid('setGridParam',
			 {
				url:common_basePath+'eqAction!queryShebeishuxingList.action?type=1&mainid=<%=request.getParameter("mainid")%>&temp='+Math.round(Math.random()*10000)
			 }).trigger("reloadGrid", [{page:1}]); 
		} 
		//清空
		function reset(){
			jQuery("#shebeishuxing").val("");
		}
		 
  </script>
  <body>
  	<div id="search"  >
		<table border="0" cellpadding="4" cellspacing="1"   width="100%">
			<tr>
				<td class="td_label_user">设备属性：</td>
				<td class="td_value">
				 <input type="text"   id="shebeishuxing"   name="shebeishuxing" style="width: 100px;"  value="" />
				</td>
				<td colspan="4" align="left">
					<input type="button" class="button_b" value="查&nbsp;询" onclick="gridSearch()"/>
					<input type="button" class="button_b" value="清&nbsp;空" onclick="reset()"/>
				</td>
			</tr>
			</table>		
	</div>
    <div style="float: left">
        <table id='fromTable'></table><div id='fromPager'></div>
    </div>
    <div style="width:60px;height:200px;float:left;align: center;padding-top: 100px;">
        <button id="to" class="button_b" >选&nbsp;择</button><br /><br />     
        <button id="from" class="button_b" >删&nbsp;除</button><br />
    </div>
    <div style="float: left">
        <table id='toTable'></table><div id='toPager'></div>
    </div>
    <div style="width:750px;clear: both;text-align: center;height:30px">
        <button id="clos" class="button_b">确&nbsp;定</button>
    </div>
  </body>
</html>
